/**
 * deploy contract to ethereumn-like blockchain, not using the upgrades plugin
 * */
const { ethers, upgrades } = require("hardhat");

async function main() {
  const [deployer] = await ethers.getSigners();

  console.log("Deploying contracts with the account:", deployer.address);

  //deploy logic contract
  const EvidenceController = await ethers.getContractFactory("EvidenceController");
  evidenceController = await EvidenceController.deploy();

  //deploy proxy admin contract
  const EvProxyAdmin = await ethers.getContractFactory("EvProxyAdmin");
  evProxyAdmin = await EvProxyAdmin.deploy();

  //deploy proxy contract
  const EvProxy = await ethers.getContractFactory("EvProxy");

  //caculate function signature of initialize()
  //For ethereum-like chain, function signature of initialize() is 0x8129fc1c
  //For fisco bcos using sm2, function signature of initialize() is 0xea605f3d
  initCode = ethers.utils.id("initialize()").substring(0,10); 

  evProxy = await EvProxy.deploy(evidenceController.address, evProxyAdmin.address, initCode);

  console.log("EvidenceController deployed at:", evProxy.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
